package com.quanyan.travel.web;

import com.quanyan.travel.api.resp.RespOutdoorActivityDetail;
import com.quanyan.travel.service.TravelDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/api/travel/thymeleaf")
public class ThymeleafController {
    @Autowired
    TravelDetailService detailService;

    private static String STATIC_HTML_URL = "travel";



    @RequestMapping(value = "/greeting", method = RequestMethod.GET)
    public String greeting(@RequestParam(name = "name", required = false, defaultValue = "world") String name, Model model) {
        model.addAttribute("xname", name);
        return "greet";
    }

    @RequestMapping(value = "/ajax", method = RequestMethod.GET)
    public String ajax(@RequestParam("username") String username) {
        return username + "hha";
    }

    @RequestMapping(value = "/webDetail", method = RequestMethod.GET)
    public String webDetail(@RequestParam(name = "activityId", required = true, defaultValue = "1") Integer activityId, Model model) {


        RespOutdoorActivityDetail activityDetail = detailService.getTravelOverviewSingle(activityId);
        if (null == activityDetail || null == activityDetail.getActivityId()) {
            return "error";
        }
        model.addAttribute("activity",activityDetail);
        return STATIC_HTML_URL +"/single_detail";
    }

    @RequestMapping(value = "/escapeClause", method = RequestMethod.GET)
    public String escapeClause() {

        return STATIC_HTML_URL +"/escape_clause";
    }

}
